package leetcode.slidwidow.marscode;

public class StrChange {


    //MarsCode字符替换与最长子串问题，滑动窗口+枚举
    public static int solution(int n, int k, String inp) {

        int maxLen = 0;

        for (char c1 = 'A'; c1 <= 'Z'; c1++) {
            for (char c2 = 'A'; c2 <= 'Z'; c2++) {
                for (int l = 0, r = 0, modifyCount = 0; r < inp.length(); r++) {
                    if (inp.charAt(r) != c1 && inp.charAt(r) != c2) {
                        modifyCount++;
                        while (modifyCount > k) {
                            if (inp.charAt(l) != c1 && inp.charAt(l) != c2) {
                                modifyCount--;
                            }
                            l++;
                        }
                    }
                    maxLen = Math.max(maxLen, r - l + 1);
                }
            }
        }
        return maxLen;
    }

    public static void main(String[] args) {

        System.out.println(solution(6, 1, "ABCBAD") == 5);
        System.out.println(solution(5, 1, "AEABD") == 4);
    }






}
